//
//  MainViewController.swift
//  WppSinaWeibo
//
//  Created by 吴盼盼 on 16/1/11.
//  Copyright © 2016年 wpp. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    //添加监听事件
    @objc private func plusBtnDidClick() {
        print(__FUNCTION__)
    }

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        // 系统的tabBar是只读属性不能直接修改,但是能通过KVC间接修改 (替换)
//        print(tabBar.classForCoder)
        let mainTabBar = MainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
//        print(tabBar.classForCoder)
        mainTabBar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
        
        
        addKidViewControllers()
    }
    
    func addKidViewControllers() {
        addKidViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addKidViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addKidViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addKidViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }
    
    //添加子视图控制器
    func addKidViewController(vc: UIViewController, imageName: String, title: String) {
        //实例化VC
//        let home = HomeTableViewController()
        
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        //设置title
//        home.tabBarItem.title = "首页"
//        home.navigationItem.title = "首页"
        vc.title = title
        //修改显示样式(不会造成渲染)
        self.tabBar.tintColor = UIColor.orangeColor()
        //导航控制器
        let nav = UINavigationController(rootViewController: vc)
        
        //添加子视图
        addChildViewController(nav)
    }
   
}
